"use client";

import { useMenuStore } from "@/store/menuStore";
import { useUserStore } from "@/store/userStore";
// import DefaultLayout from "@/ui/layout/Default";
import ProLayout from "@/ui/layout/ProLayout";
import { StyleProvider } from "@ant-design/cssinjs";
import { useRequest } from "ahooks";
import { message } from "antd";

// 布局
export default function Layout({ children }: { children: React.ReactNode }) {
  const userStore = useUserStore();
  const menuStore = useMenuStore();

  const { loading: userLoading } = useRequest(userStore.getUserInfo, {
    onError: (error: any) => {
      message.error(error.msg);
    },
  });

  const { loading: menuLoading } = useRequest(menuStore.getMenus, {
    onError: (error: any) => {
      message.error(error.msg);
    },
  });

  return (
    <StyleProvider layer>
      <ProLayout loading={userLoading || menuLoading}>{children}</ProLayout>
    </StyleProvider>
  );
}
